import axios from "axios";

const service = axios.create({
    baseURL: '/api',
});

// 添加请求拦截器
service.interceptors.request.use(
    config => {
        // 假设你的token存储在Vuex、Pinia或者本地存储中，这里直接用一个变量代替
        // 请确保在实际应用中从安全的地方获取token
        const token = "9ior41AF0xTIbIG2pRnnbZi0+fEeMx8pywnIlrmTwo5FbqJ9lWrSWOxp9MkpKiNtedtUafqvzIwpFKrwuMs";
        if (token) {
            config.headers['token'] = ` ${token}`;
        }
        return config;
    },
    error => {
        return Promise.reject(error);
    }
);

// 添加响应拦截器
service.interceptors.response.use(resp => {
    return resp.data;
}, error => {
    return Promise.reject(error);
});

export default service;